// Most common use
id mutableDictionary = [NSMutableDictionary dictionary];
// May not be what you want
id dictionary = [NSDictionary dictionary];
id preferences = [NSMutableDictionary
dictionaryWithObjects:@("window", "non- smoking", "747")
forKeys:@("seatAssignment", "smoking", "aircraft")];
id customerPreferences = [NSDictionary dictionaryWithObjectsAndKeys:
seatingPreference, @"seatAssignment",
smokingPreference, @"smoking",
aircraftPreference, @"aircraft", nil];
id index;
id keys = [dictionary allKeys];
for (index = 0; index < [keys count]; index++) {
value = [dictionary objectForKey:[keys
objectAtIndex:index]];
// Use the value
}
id choices = @{"Steak" = 3; "Seafood" = 2; "Pasta" = 1};
id keys = [choices keysSortedByValueUsingSelector:@"compare:"];
id preferences = [NSMutableDictionary
dictionaryWithObjects:@("window", "non- smoking", "747")
forKeys:@("seatAssignment", "section", "aircraft")];
id sectionPreference = [dictionary objectForKey:@"section"];
id dictionary = [NSMutableDictionary dictionaryWithDictionary:
@{"seatAssignment" = "window"}];
[dictionary setObject:@"non-smoking" forKey:@"section"];
[dictionary setObject:@"aisle" forKey:@"seatAssignment"];
id preferences = [NSMutableDictionary
dictionaryWithObjects:@("window", "non- smoking", "747")
forKeys:@("seatAssignment", "section", "aircraft")];
id description = [preferences description];
id defaults = [NSMutableDictionary
dictionaryWithContentsOfFile:path];
[defaults setObject:newLanguagePreference forKey:@"Language"];
[defaults writeToFile:path atomically:YES];
Table of Contents
Next Section